// Learn TypeScript:
//  - https://docs.cocos.com/creator/manual/en/scripting/typescript.html
// Learn Attribute:
//  - https://docs.cocos.com/creator/manual/en/scripting/reference/attributes.html
// Learn life-cycle callbacks:
//  - https://docs.cocos.com/creator/manual/en/scripting/life-cycle-callbacks.html

import VirtualItem from "../../ui/VirtualItem";
import { VirtualArgs } from "../../ui/VirtualList";

const {ccclass, property} = cc._decorator;

export interface StockItemArgs extends VirtualArgs {
    ts_code: string;
    name: string;
    listDate: string;
    market: any,
    upLimitCount: number,
    upLimitContinue: number,
    upLimitType: number,
    upFloat: number, 
    tradeCount: number,
}

@ccclass
export default class StockInfoItem extends VirtualItem<StockItemArgs> {

    @property(cc.Label)
    textLabel: cc.Label = null;

    market: any = null;

    public onRefresh(args: StockItemArgs) {
        let strData = (this.dataIdx + 1) + '';
        strData += '  ' + args.ts_code;
        strData += '  ' + args.name;
        if (args.upLimitCount) {
            if (args.upLimitType > 20) {
                strData += '  涨停 ' + args.upLimitCount + ' 次';
            } else {
                strData += '  大于' + args.upLimitType + '% ' + args.upLimitCount + ' 次';
            }
            
            strData += '  连板 ' + args.upLimitContinue + ' 次';
        } else if (args.upFloat != null) {
            strData += `  ${args.tradeCount}日涨幅:${args.upFloat}%`;
        }

        if (args.listDate && args.listDate !== '') {
            strData += '  上市时间:' + args.listDate;
        }
        
        if (args.market) {
            strData += '  市值' + Math.ceil(args.market.total_mv / 10000) + '亿';
            strData += '  市盈率' + args.market.pe_ttm;
            strData += '  市净率' + args.market.pb;
        }
        this.textLabel.string = strData;
        this.market = args.market;
    }

    onClick () {
        if (this.market) {
            cc.director.emit('SelectStockEvent', this.dataIdx);
        }
       
    }

    // update (dt) {}
}
